<?php session_start();
	$host  = $_SERVER['HTTP_HOST'];
	if ($_SERVER['SERVER_NAME'] == 'localhost'){$uri="/kalender";}else{$uri="";}	
	if(isset($_GET['msg']) && $_GET['msg']=='5'){		
		$cookies = explode(';', $_SERVER['HTTP_COOKIE']);
		foreach($cookies as $cookie) {
			$parts = explode('=', $cookie);
			$name = trim($parts[0]);
			setcookie($name, '', time()-1000);
			setcookie($name, '', time()-1000, '/');
			setcookie($name, '', time()-1000, '/', 'kalender.com.ar');
		}
		$host  = $_SERVER['HTTP_HOST'];
		header("Location: http://$host/index.php");	
	}else{ //dibujo la pantalla de login
		
	
		if ((!isset($_GET['error'])) && isset($_COOKIE["kaluname"]) && isset($_COOKIE["kalpword"]) && $_COOKIE["kaluname"] != "" && $_COOKIE["kalpword"] != "") {?>		
		<HTML>
	    <HEAD>
			<TITLE></TITLE>
	    </HEAD>
		<BODY> 
			<div style="display:none">
				<form id='autologin' action="actions/validar_usuario.php" method="post">
					<input id="autologinUsername" type="text" name="usuario" value="<?php echo($_COOKIE["kaluname"]);?>" />
					<input id="autologinPassword" type="password" name="password" value="<?php echo($_COOKIE["kalpword"]);?>" />				
				</form>
			</div>
			<script>
				document.forms['autologin'].submit();
			</script>		 
		</BODY>
		</HTML>
	<?php 			
		}else{ //dibujo la pantalla de login

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
 <HEAD>
  <TITLE> Kalender </TITLE>
  <meta name="tipo_contenido"  content="text/html;" http-equiv="content-type" charset="utf-8">
  <meta name="title" content="Kalender">
  <meta name="description" content="Kalender" />
  <meta name="keywords" content="Kalender" />
  <?php
	  include("globals/links.php");
  ?>    
  <script type="text/javascript">
  	$(document).ready(function(){
			$("#usuario").keypress(function(e){if (e.keyCode == 13 || e.charCode == 13){try_login();}});
			$("#password").keypress(function(e){if (e.keyCode == 13 || e.charCode == 13){try_login();}});
	});	
  </script>
	
</HEAD>
<BODY style="background-image:none; background-color:#E6E6E6;"> 
<div class="body">
	<div class="pr" style="height:100%;">
	  	<?php
			echo("<div style='display:none'>");
			print_r($_COOKIE);
			echo("</div>");
		  include("globals/init_header.php");
		?> 
		<form id='login' action="actions/validar_usuario.php" method="post">
			<input type="hidden" name="rme" value="si"/>
			<div class="backgris2 pr" style="height:70%">				
				<div class="pr" style="color:#fff; padding-top:40px; width:100%;">
					
					<div class="pr letragris" style="left:50%; width:400px; margin-left:-300px; height:200px;">
						<div class="pr" style="height:35px;">
							<div class="input_back_index fr">
								<input type="text" id="usuario" name="usuario" value="" size="17" maxlength="30"/>
							</div>
							<div class="fr" style="margin-right:20px; margin-top:1px; font-size:16px;">Usuario:</div>
						</div>	
						<div class="pr" style="height:35px;">
							<div class="input_back_index fr">
								<input type="password" id="password" name="password" value="" size="17" maxlength="30"/>
							</div>
							<div class="fr" style="margin-right:20px; margin-top:2px; font-size:16px;">Contrase&ntilde;a:</div>
						</div>
						<div class="pr" style="height:25px;">						
							<a style="color:#333" class="fr" href="reset_password.php">Olvid&oacute; su contrase&ntilde;a?</a>
						</div>
						<div class="pr" style="height:25px;">						
							<img class="fr" style="cursor:pointer;" src="images/entrar_normal.png" 
								onmousedown="this.src='images/entrar_mousedown.png'"
								onmouseup="this.src='images/entrar_normal.png'"
								onmouseover="this.src='images/entrar_mouseover.png'"
								onmouseout="this.src='images/entrar_normal.png'" onClick="try_login()"/>
						</div>
						
						<?php 
							$wrong_user1 = "display:none";
							$wrong_pass1 = "display:none";
							if(isset($_GET['error']) && $_GET['error']=='1'){
								$wrong_user1 = "display:block";
							}else if(isset($_GET['error']) && $_GET['error']=='2'){
								$wrong_pass1 = "display:block";
							}
						?>
						
						<div id="wrong_user1" class="pa" style="right:-170px; top:4px; <?php echo($wrong_user1);?>">
							<img src="images/alerta_usu_pasw.png"/> El usuario no es correcto.
						</div>						
						<div id="wrong_pass1" class="pa" style="right:-190px; top:40px; overflow:visible; <?php echo($wrong_pass1);?>">
							<img src="images/alerta_usu_pasw.png"/> La contrase&ntilde;a no es correcta.
						</div>
					</div>				
				</div>					
			</div>
		</form>	
	</div>
</div>
</BODY>
</HTML>

<?php }} //del if grande ?>